<?php

namespace App\Http\Controllers\Api;

use App\Models\Renting;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    // 获取用户信息
    public function getuserinfo(Request $request)
    {
        $id   = $request->get('openid');
        $data = Renting::where('openid', $id)->get();
        // dump($data);
        return json_decode($data);
    }

    // 保存用户信息
    public function userinfo(Request $request)
    {
        $openid = $request->get('openid');
        $data   = $request->except('openid');
        Renting::where('openid', $openid)->update($data);
        return ['status' => 200, 'msg' => '修改资料成功'];
    }

    // 保存图片信息
    public function upfile(Request $request)
    {
        if ($request->hasFile('file')) {
            $ret = $request->file('file')->store('', 'wximg');
            $pic = '/uploads/wximg/images/' . $ret;
            return ['status' => 200, 'pic' => $pic, 'img' => config('url.domain') . $pic];
        }
        return ['status' => 1005, 'msg' => '未上传图片'];
    }
}
